# 字典创建
dt = {}
print(dt)

dt1 = {'a':3,'b':4,'c':2,'d':8}
print('dt1------->',dt)

# dict(maping)----->从映射对象（键，值）对新字典初始化
dt2 = dict(zip(['a','b','c','d'],['a','b','c']))
print('dt2------>',dt2)

# dict(iterable)----->通过iterable可迭代对象对新字典进行初始化
dt3 = dict([('a',11),('b',12)])
print('dt3------>',dt3)

# dict(**kwargs)---->在关键字参数列表中使用name=value对新字典初始化
dt4 = dict(e=12,f=15)
print('dt4------>',dt4)

dt5 =dict([('a',11),('b',12)],c=11)
print(dt5)

# dict.fromkeys(iterable,value)
res = dict.fromkeys('asc',12)
print('res------>',res)

res1 = dict.fromkeys(['a','b','c','d'],12)
print('res1------>',res1)

res2 = dict.fromkeys(('a','b','c','d'),13)
print('res2------>',res2)

res3 = dict.fromkeys(('a','b','c','d'),1)
print('res3------>',res3)

# 成员判断
res = 'a' in dt5
print(res)

res1 = 'g' not in dt5.keys()
print(res1) 

res2 = 11 in dt5.values()
print(res2)

# 循环遍历
for key in dt2:
    print(key)

for key in dt3.keys():
    print(key)

for value in dt3.values():
    print(value)

for key,value in dt4.items():
    print(key,value)

print(dt4.items())
print(type(dt4.items))

# 增
print('===========增============')
print('dt4------>',dt4)
dt4['g'] = 15
print(dt4)






# 删
print(dt2)
res6 = dt2.pop('a',-1) # key值必须给出,key值没有返回默认值
print(res6)
print('dt2----->pop(key)',dt2)

res7 = dt2.popitem() # 随机弹出字典中的一组键值对
print('res7------->',res7)
print('dt2------>',dt2) 

res8 = dt2.clear()
print('res8-------->clear()',res8)
print(dt2)

# 改
print('dt3------->',dt3)
dt3['a'] = 9999
print(dt3)

# 把字典dt3中的值更新到字典dt2中
print('dt2----->',dt2)
print('dt3----->',dt3)
dt2.update(dt3)
print('dt2--------->',dt2)


# 查
#查找字典中是否存在键‘x’,找不到就新增
res = dt4.setdefault('x',12)
print(dt4)

res5 = dt4.get('a',-1) #找不到返回默认值
print('res5------->',res5)


# 内置方法
print('dt1------>',dt1)
print('len()------->',len(dt1))

print('max()---------->',max(dt1.values()))

print('min()----------->',min(dt1))

print('sorted--------->',sorted(dt1.values()))